package edu.nf.project.services.storeOperation.impl;

import edu.nf.project.mappers.storeOperation.convention.OrderStatisticsMapper;
import edu.nf.project.services.exception.derivedAnomalies.OrderStatisticsException;
import edu.nf.project.services.storeOperation.OrderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 订单统计Service实现类
 */
@Service
public class OrderStatisticsServiceImpl implements OrderStatisticsService {

    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;

    @Override
    public BigDecimal getTotalRevenue(LocalDateTime startTime, LocalDateTime endTime) {
        try {
            return orderStatisticsMapper.getTotalRevenue(startTime, endTime);
        } catch (Exception e) {
            throw new OrderStatisticsException(70000, "获取总营业额失败：" + e.getMessage());
        }
    }

    @Override
    public Long getTotalOrderCount(LocalDateTime startTime, LocalDateTime endTime) {
        try {
            return orderStatisticsMapper.getTotalOrderCount(startTime, endTime);
        } catch (Exception e) {
            throw new OrderStatisticsException(70001, "获取总订单数失败：" + e.getMessage());
        }
    }

    @Override
    public BigDecimal getAverageOrderAmount(LocalDateTime startTime, LocalDateTime endTime) {
        try {
            return orderStatisticsMapper.getAverageOrderAmount(startTime, endTime);
        } catch (Exception e) {
            throw new OrderStatisticsException(70002, "获取平均客单价失败：" + e.getMessage());
        }
    }
} 